﻿public class Solution {
    public int[] Intersection(int[] nums1, int[] nums2)
    {
        HashSet<int> hashNum1 = new HashSet<int>(nums1);
        HashSet<int> hashNum2 = new HashSet<int>(nums2);

        hashNum1.IntersectWith(hashNum2);
        return hashNum1.ToArray();
    }

    public static void Main(string[] args)
    {
        int[] nums1 = [1, 2, 2, 1];
        int[] nums2 = [2, 2];
        
        // 求交集
        Solution solution = new Solution();
        int[] interNums = solution.Intersection(nums1, nums2);
        
        // 打印
        foreach (int n in interNums)
        {
            Console.Write($"{n} ");
        }
    }
}